home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F28196_Calendar5.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2001-10-04  |  10.3 KB  |  295 lines

  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  2.   <xsl:include href="datetime_lib.xsl"/>
  3.   
  4.   <xsl:output method="html" encoding="ISO-8859-1" />
  5.   
  6.   <xsl:param name="today" select="20010827"/>
  7.   <xsl:param name="firstWeekDay" select="1"/>
  8.   
  9.   <xsl:variable name="year" select="substring($today, 1, 4)"/>
  10.   
  11.   <xsl:variable name="n-abbreviatedDOW">
  12.     <day>Mo</day>
  13.     <day>Tu</day>
  14.     <day>We</day>
  15.     <day>Th</day>
  16.     <day>Fr</day>
  17.     <day>Sa</day>
  18.     <day>Su</day>
  19.   </xsl:variable>
  20.   
  21.   <xsl:variable name="abbreviatedDOW" 
  22.                 select="document('')/*/xsl:variable[@name='n-abbreviatedDOW']/*"/>
  23.   
  24.   <xsl:template match="/">
  25.     <html>
  26.      <head />
  27.   Today is: <xsl:text/>
  28.         <xsl:call-template name="named-day-of-week">
  29.           <xsl:with-param name="date" select="$today"/>
  30.         </xsl:call-template>
  31.         <p />
  32.         
  33.         <table>
  34.           <xsl:call-template name="displayQuarter">
  35.             <xsl:with-param name="year" select="$year"/>
  36.             <xsl:with-param name="Q" select="1"/>
  37.           </xsl:call-template>
  38.  
  39.           <xsl:call-template name="displayQuarter">
  40.             <xsl:with-param name="year" select="$year"/>
  41.             <xsl:with-param name="Q" select="2"/>
  42.           </xsl:call-template>
  43.  
  44.           <xsl:call-template name="displayQuarter">
  45.             <xsl:with-param name="year" select="$year"/>
  46.             <xsl:with-param name="Q" select="3"/>
  47.           </xsl:call-template>
  48.  
  49.           <xsl:call-template name="displayQuarter">
  50.             <xsl:with-param name="year" select="$year"/>
  51.             <xsl:with-param name="Q" select="4"/>
  52.           </xsl:call-template>
  53.           
  54.         </table>
  55.     </html>
  56.   </xsl:template>
  57.   
  58.   <xsl:template name="displayQuarter">
  59.       <xsl:param name="year"/>
  60.       <xsl:param name="Q"/>
  61.   
  62.     <xsl:variable name="month" select="($Q - 1) * 3 + 1"/>
  63.     
  64.     <xsl:variable name="fMonth" select="concat(substring('00', 1, 2 - string-length($month)), $month)"/>
  65.     <xsl:variable name="fMonth2" select="concat(substring('00', 1, 2 - string-length($month + 1)), $month + 1)"/>
  66.     <xsl:variable name="fMonth3" select="concat(substring('00', 1, 2 - string-length($month + 2)), $month + 2)"/>
  67.     
  68.     <tr valign="top">
  69.  
  70.       <td>
  71.             <xsl:call-template name="displayMonth">
  72.               <xsl:with-param name="date" 
  73.                               select="concat($year, $fMonth, '01')"/>
  74.             </xsl:call-template>
  75.         </td>
  76.       <td>
  77.             <xsl:call-template name="displayMonth">
  78.               <xsl:with-param name="date" 
  79.                               select="concat($year, $fMonth2, '01')"/>
  80.             </xsl:call-template>
  81.         </td>
  82.       <td>
  83.             <xsl:call-template name="displayMonth">
  84.               <xsl:with-param name="date" 
  85.                               select="concat($year, $fMonth3, '01')"/>
  86.             </xsl:call-template>
  87.         </td>
  88.     </tr>
  89.     </xsl:template>
  90.  
  91.   
  92.   <xsl:template name="get-month">
  93.     <xsl:param name="date"/>
  94.     <xsl:variable name="tr-date" select="translate($date, '-', '')"/>
  95.     <xsl:value-of select="substring($tr-date, 5,2)"/>
  96.   </xsl:template>
  97.   
  98.   <xsl:template name="get-year">
  99.     <xsl:param name="date"/>
  100.     <xsl:variable name="tr-date" select="translate($date, '-', '')"/>
  101.     <xsl:value-of select="substring($tr-date, 1,4)"/>
  102.   </xsl:template>
  103.   
  104.   <xsl:template name="get-day">
  105.     <xsl:param name="date"/>
  106.     <xsl:variable name="tr-date" select="translate($date, '-', '')"/>
  107.     <xsl:value-of select="substring($tr-date, 7)"/>
  108.   </xsl:template>
  109.   
  110.   <xsl:template name="displayMonth">
  111.     <xsl:param name="date"/>
  112.     
  113.     <xsl:variable name="month">
  114.       <xsl:call-template name="get-month">
  115.         <xsl:with-param name="date" select="$date"/>
  116.       </xsl:call-template>
  117.     </xsl:variable>
  118.     
  119.     <xsl:variable name="year">
  120.       <xsl:call-template name="get-year">
  121.         <xsl:with-param name="date" select="$date"/>
  122.       </xsl:call-template>
  123.     </xsl:variable>
  124.     
  125.     <xsl:variable name="nameOfMonth" 
  126.     select="substring-before(substring-after($default-month-names, concat('[', $month, ']')), '[')"/>
  127.     <xsl:text> </xsl:text>
  128.     <center>
  129.         <table border="0" cellpadding="6" cellspacing="0" width="80">
  130.         
  131.                 <tr bgColor="#808080">
  132.                     <td colSpan="5">
  133.                       <font color="#f8f8f8">
  134.                         <strong><xsl:value-of select="$nameOfMonth"/></strong>
  135.                   </font>
  136.                     </td>
  137.                     <td colSpan="2">
  138.                       <font color="#f8f8f8">
  139.                          <strong><xsl:value-of select="$year"/></strong>
  140.                 </font>
  141.             </td>
  142.           </tr>
  143.         <tr bgcolor="#E0E0E0">
  144.           <xsl:for-each select="$abbreviatedDOW">
  145.             <xsl:variable name="thisPos">
  146.               <xsl:choose>
  147.                 <xsl:when test="$firstWeekDay = 1">
  148.                  <xsl:value-of select="position()"/>
  149.                 </xsl:when>
  150.                 <xsl:when test="$firstWeekDay = 0">
  151.                   <xsl:choose>
  152.                     <xsl:when test="position() = 1">7</xsl:when>
  153.                     <xsl:otherwise>
  154.                         <xsl:value-of select="position() - 1"/>
  155.                     </xsl:otherwise>
  156.                   </xsl:choose>
  157.                 </xsl:when>
  158.               </xsl:choose>
  159.             </xsl:variable>
  160.             <td>
  161.               <font color="#0000E0">
  162.                 <xsl:value-of select="$abbreviatedDOW[position() = $thisPos]"/>
  163.               </font>
  164.             </td>
  165.           </xsl:for-each>
  166.         </tr> 
  167.         
  168.         <xsl:variable name="firstDayOfMonth" select="concat(substring($date, 1, 6), '01')"/>
  169.         
  170.         <xsl:variable name="week-number">
  171.           <xsl:call-template name="week-number">
  172.             <xsl:with-param name="date" select="$firstDayOfMonth"/>
  173.           </xsl:call-template>
  174.         </xsl:variable>
  175.         
  176.         <xsl:call-template name="displayWeeks">
  177.           <xsl:with-param name="year" select="$year"/>
  178.           <xsl:with-param name="month" select="$month"/>
  179.           <xsl:with-param name="week" select="$week-number"/>
  180.         </xsl:call-template>
  181.         
  182.          </table>
  183.      </center>
  184.   </xsl:template>
  185.   
  186.   <xsl:template name="displayWeeks">
  187.      <xsl:param name="year"/>
  188.      <xsl:param name="month"/>
  189.      <xsl:param name="week"/>
  190.      
  191.      <xsl:variable name="weekStartDate">
  192.        <xsl:call-template name="week-number-to-date">
  193.          <xsl:with-param name="week" select="$week"/>
  194.          <xsl:with-param name="year" select="$year"/>
  195.        </xsl:call-template>
  196.      </xsl:variable>
  197.      
  198.      <tr align="right" bgcolor="white">
  199.        <xsl:variable name="dOffset">
  200.          <xsl:choose>
  201.           <xsl:when test="$firstWeekDay = 1">0</xsl:when>
  202.           <xsl:when test="$firstWeekDay = 0">1</xsl:when>
  203.          </xsl:choose>
  204.        </xsl:variable>
  205.        <xsl:for-each select="$abbreviatedDOW">
  206.          <xsl:variable name="thisDate">
  207.            <xsl:call-template name="date-add">
  208.              <xsl:with-param name="date" select="$weekStartDate"/>
  209.              <xsl:with-param name="add" select="position() - 1 - $dOffset"/>
  210.            </xsl:call-template>
  211.          </xsl:variable>
  212.              
  213.              <xsl:variable name="month-of-this-date">
  214.               <xsl:call-template name="get-month">
  215.                 <xsl:with-param name="date" select="$thisDate"/>
  216.               </xsl:call-template>
  217.              </xsl:variable>
  218.          <td>
  219.            <xsl:choose>
  220.              <xsl:when test="$month-of-this-date = $month">
  221.                <xsl:variable name="color">
  222.                    <xsl:choose>
  223.                      <xsl:when test="$today = translate($thisDate, '-','')">
  224.                       <xsl:value-of select="'red'"/>
  225.                      </xsl:when>
  226.                      <xsl:when test="position() = 7
  227.                                   or (position() = 6 and $firstWeekDay = 1)
  228.                                   or (position() = 1 and $firstWeekDay = 0)">
  229.                         <xsl:value-of select="'navy'"/>
  230.                      </xsl:when>
  231.                      <xsl:otherwise>black</xsl:otherwise>
  232.                    </xsl:choose>
  233.                </xsl:variable>
  234.                <font color="{$color}">
  235.                    <xsl:variable name="thisDay">
  236.                        <xsl:call-template name="get-day">
  237.                          <xsl:with-param name="date" select="$thisDate"/>
  238.                        </xsl:call-template>
  239.                    </xsl:variable>
  240.  
  241.                    <xsl:variable name="formattedDay">
  242.                        <xsl:choose>
  243.                          <xsl:when test="$thisDay < 10">
  244.                            <xsl:value-of select="substring($thisDay, 2)"/>
  245.                          </xsl:when>
  246.                          <xsl:otherwise>
  247.                            <xsl:value-of select="$thisDay"/>
  248.                          </xsl:otherwise>
  249.                        </xsl:choose>
  250.                    </xsl:variable>
  251.                    
  252.                    <xsl:choose>
  253.                      <xsl:when test="$color = 'navy'">
  254.                        <strong><xsl:value-of select="$formattedDay"/></strong>
  255.                      </xsl:when>
  256.                      <xsl:otherwise>
  257.                      <xsl:value-of select="$formattedDay"/>
  258.                      </xsl:otherwise>
  259.                    </xsl:choose>
  260.                </font>
  261.                
  262.              </xsl:when>
  263.              <xsl:otherwise>
  264.                <xsl:text> </xsl:text>
  265.              </xsl:otherwise>
  266.            </xsl:choose>
  267.          </td>
  268.              <xsl:if test="position() = 7">
  269.                  <xsl:variable name="next-week-date">
  270.                    <xsl:call-template name="date-add">
  271.                      <xsl:with-param name="date" select="$weekStartDate"/>
  272.                      <xsl:with-param name="add" select="7"/>
  273.                    </xsl:call-template>
  274.                  </xsl:variable>
  275.                      
  276.                      <xsl:variable name="month-of-next-week">
  277.                       <xsl:call-template name="get-month">
  278.                         <xsl:with-param name="date" select="$next-week-date"/>
  279.                       </xsl:call-template>
  280.                      </xsl:variable>
  281.              
  282.                  <xsl:if test="$month = $month-of-next-week">
  283.                      <xsl:call-template name="displayWeeks">
  284.                              <xsl:with-param name="year" select="$year"/>
  285.                              <xsl:with-param name="month" select="$month"/>
  286.                              <xsl:with-param name="week" select="$week + 1"/>
  287.                      </xsl:call-template>
  288.                  </xsl:if>
  289.            </xsl:if>
  290.        </xsl:for-each>
  291.      </tr>
  292.      
  293.    </xsl:template>
  294. </xsl:stylesheet>
  295.